import 'package:flutter/material.dart';
import 'package:flutter_lang/flutter_lang.dart';
import 'package:wallet_home/module_config.dart';

typedef GestureRadioSelectCallback = void Function(int position); //

class TransferStepperWidget extends StatefulWidget {
  final double radioRadius;
  final EdgeInsetsGeometry textPadding;
  final double lineWidth;
  final double lineHeight;
  final Color lineColor;
  final double innerCircleRadius;
  final TextStyle labelTextStyle;
  final Color innerCircleColor;
  final EdgeInsetsGeometry innerCirclePadding;
  final Color outerCircleColor;
  final GestureRadioSelectCallback callback;
  final int initialPosition;

  TransferStepperWidget({
    Key key,
    this.radioRadius = 15,
    this.textPadding = const EdgeInsets.only(top: 5),
    this.lineWidth = 50,
    this.innerCircleRadius = 15,
    this.innerCircleColor = Colors.red,
    this.innerCirclePadding = const EdgeInsets.all(6),
    this.lineHeight = 5,
    this.outerCircleColor = const Color(0xFFEEEEEE),
    this.callback,
    this.labelTextStyle = const TextStyle(color: Colors.grey, fontSize: 14),
    this.lineColor = const Color(0xFFEEEEEE),
    this.initialPosition,
  }) : super(key: key);

  @override
  _TransferStepperState createState() => _TransferStepperState();
}

class _TransferStepperState extends State<TransferStepperWidget> {
  int groupValue = 0;
  List<String> labels = [
    "${WXLang.$t("home_slow",package: ModuleConfig.moduleName)}",
    "${WXLang.$t("home_recommend",package: ModuleConfig.moduleName)}",
    "${WXLang.$t("home_fast",package: ModuleConfig.moduleName)}"
  ];

  @override
  void initState() {
    super.initState();
    groupValue = widget.initialPosition;
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Row(
      children: [
        Column(
          children: [
            GestureDetector(
              child: Container(
                  height: widget.radioRadius * 2,
                  width: widget.radioRadius * 2,
                  decoration: BoxDecoration(
                      color: widget.outerCircleColor,
                      borderRadius: BorderRadius.all(
                          Radius.circular(widget.radioRadius))),
                  child: Offstage(
                      offstage: groupValue != 0,
                      child: Container(
                        margin: widget.innerCirclePadding,
                        decoration: BoxDecoration(
                            color: widget.innerCircleColor,
                            borderRadius: BorderRadius.all(
                                Radius.circular(widget.innerCircleRadius))),
                      ))),
              onTap: () {
                groupValue = 0;
                if (widget.callback != null) {
                  widget.callback(groupValue);
                }
                setState(() {});
              },
            ),
            Padding(
              padding: widget.textPadding,
              child: Text(
                labels[0],
                style: widget.labelTextStyle,
              ),
            ),
          ],
        ),
        Container(
          margin:
              EdgeInsets.only(bottom: widget.radioRadius + widget.lineHeight + 3),
          height: widget.lineHeight,
          width: widget.lineWidth,
          color: widget.lineColor,
        ),
        Column(
          children: [
            GestureDetector(
              child: Container(
                  height: widget.radioRadius * 2,
                  width: widget.radioRadius * 2,
                  decoration: BoxDecoration(
                      color: widget.outerCircleColor,
                      borderRadius: BorderRadius.all(
                          Radius.circular(widget.radioRadius))),
                  child: Offstage(
                      offstage: groupValue != 1,
                      child: Container(
                        margin: widget.innerCirclePadding,
                        decoration: BoxDecoration(
                            color: widget.innerCircleColor,
                            borderRadius: BorderRadius.all(
                                Radius.circular(widget.innerCircleRadius))),
                      ))),
              onTap: () {
                groupValue = 1;
                if (widget.callback != null) {
                  widget.callback(groupValue);
                }
                setState(() {});
              },
            ),
            Padding(
              padding: widget.textPadding,
              child: Text(
                labels[1],
                style: widget.labelTextStyle,
              ),
            ),
          ],
        ),
        Container(
          margin:
              EdgeInsets.only(bottom: widget.radioRadius + widget.lineHeight + 3),
          height: widget.lineHeight,
          width: widget.lineWidth,
          color: widget.lineColor,
        ),
        Column(
          children: [
            GestureDetector(
              child: Container(
                  height: widget.radioRadius * 2,
                  width: widget.radioRadius * 2,
                  decoration: BoxDecoration(
                      color: widget.outerCircleColor,
                      borderRadius: BorderRadius.all(
                          Radius.circular(widget.radioRadius))),
                  child: Offstage(
                      offstage: groupValue != 2,
                      child: Container(
                        margin: widget.innerCirclePadding,
                        decoration: BoxDecoration(
                            color: widget.innerCircleColor,
                            borderRadius: BorderRadius.all(
                                Radius.circular(widget.innerCircleRadius))),
                      ))),
              onTap: () {
                groupValue = 2;
                if (widget.callback != null) {
                  widget.callback(groupValue);
                }
                setState(() {});
              },
            ),
            Padding(
              padding: widget.textPadding,
              child: Text(
                labels[2],
                style: widget.labelTextStyle,
              ),
            )
          ],
        )
      ],
    ));
  }
}
